package cn.tedu.boot01.controller;


import cn.tedu.boot01.entity.Bmi;
import cn.tedu.boot01.entity.Emp;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
//添加此注解后,就不用在每一个方法上添加@RequestMapping
public class BMIController {
    @RequestMapping("/b1")
    /*@ResponseBody//添加磁珠节后可以通过返回值的方式,给客户端返回数据*/
    public String b1(HttpServletRequest request) {
        Double height = Double.parseDouble(request.getParameter("height"));
        Double weight = Double.parseDouble(request.getParameter("weight"));
        Double bmi = weight / (height * height);
        if (bmi <= 18.5) {
            return "偏瘦";
        } else if (bmi <= 27) {
            return "微胖";
        } else {
            return "有点胖了";
        }
    }

    @RequestMapping("/b2")
    public String b2(Double height, Double weight) {
        double bmi = weight / (height * height);
        if (bmi <= 18.5) {
            return "偏瘦";
        } else if (bmi <= 27) {
            return "微胖";
        } else {
            return "有点胖了";
        }
    }

    @RequestMapping("/b3")
    public String p3(Bmi b) {
        //SpringMVC框架通过反射技术,将接收到的参数直接封装到对象里面
        //soutp
        Double bmi = b.getWeight() / (b.getHeight() * b.getHeight());
        if (bmi <= 18.5) {
            return "偏瘦";
        } else if (bmi <= 27) {
            return "微胖";
        } else {
            return "有点胖了";
        }
    }
}
